﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao
{
    public class IPRCuenta : Intermediario
    {
        public override void save<T>(T entity)
        {
            try
            {
                Cuenta cta = entity as Cuenta;
                cta.fechaAlta = DateTime.Now;
                dao.Cuentas.InsertOnSubmit(cta);
            }
            catch (Exception ex)
            {
                throw new Exception("IPRCuenta.Save - " + ex.Message);
            }
        }

        public override List<T> getAll<T>()
        {
            throw new NotImplementedException();
        }

        public override List<T> getByCriterio<T>(string u, string op, string c)
        {
           // return (from cta in dao.Cuentas where cta.Usuario == u && cta.Contrasenia == c select cta.Persona.Rol).ToList() as List<T>;

            List<T> listita = dao.ExecuteQuery<Cuenta>("SELECT * FROM Cuenta WHERE Cuenta.Usuario = " + u + " AND Cuenta.Contrasenia = " + " '" + c + "' AND Cuenta.fechaBaja IS NULL").ToList() as List<T>;

            return listita;
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            throw new NotImplementedException();
        }

        public override object getPorId(int id)
        {
            return (from c in dao.Cuentas where c.IdPersona == id && c.fechaBaja == null select c).SingleOrDefault();
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
            throw new NotImplementedException();
        }
    }
}

